package com.yihusitian.zsxq.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yihusitian.zsxq.pojo.data.UserDO;
import com.yihusitian.zsxq.pojo.dto.Owner;
import com.yihusitian.zsxq.pojo.dto.Task;
import com.yihusitian.zsxq.service.IDGenerator;
import com.yihusitian.zsxq.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yihusitian.zsxq.service.TaskService;
import com.yihusitian.zsxq.mapper.TaskMapper;
import com.yihusitian.zsxq.pojo.data.TaskDO;

/**
 * @Description TODO
 * @Author LeeHo
 * @Date 2021-03-26 19:39:25
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, TaskDO> implements TaskService {

    @Autowired
    private UserService userService;

    @Override
    public void creatTask(Task task, Long topicId) {
        if (task == null) {
            return;
        }
        UserDO owner = userService.createOrUpdate(task.getOwner());
        TaskDO.builder().id(IDGenerator.generateId()).text(StrUtil.emptyToDefault(task.getText(), StrUtil.EMPTY)).topicId(topicId).ownerId(owner.getId()).build().insert();
    }
}